<template>
  <div>
      用户名：<input type="text" v-model="username" @blur="uui">{{error_name}}<br>
      密码：<input type="text" v-model="password"><br>
      邮箱：<input type="text" v-model="email"><br>
      验证码：<input type="text" v-model="code"><img v-bind:src="'http://127.0.0.1:8000/image_code?uuid='+uuid" @click="bian"><br>
      <input type="button" value="注册" @click="reg">
  </div>
</template>

<script>

import {guuid} from '../utils/uuid'

export default {
    data() {
        return {
            username:"",
            password:"",
            email:"",
            code:"",
            error_name:'',
            uuid:guuid(),
        }
    },methods:{
    bian(){
      this.uuid=guuid()
      return this.uuid
    },
    uui(){
    //         const re = /^\w{4,8}$/
    //         if(re.test(this.username)){
    //         this.error_name = '√'
    //         }else{
    //         this.error_name = '请输入4-8个字节符'
    //         }
    //     },
        const data={
            "username":this.username
        }
      this.axios.post("/zhengce/",data).then(resp=>{
        console.log(resp.data.msg)
        alert(resp.data.msg)
      }).catch(error=>{
        console.log(error.response)
        alert(error.response.data.msg)
      })
    },
    reg(){
        console.log(this.uuid)
        const data={
            'username':this.username,
            'password':this.password,
            'email':this.email,
            'code':this.code,
            'uuid':this.uuid,
        }
        this.axios.post('/zhengce1/',data).then(resp=>{
            console.log(resp.data)
        }).catch(error=>{
            console.log(error.respons)
        })
    }
        }
}
</script>

<style>

</style>